package suanfa;

import java.util.Arrays;

/**
 * Description:
 * Author:    Dane
 * CreateTime:2024/8/28-下午9:42
 * Since  :   1.0
 * Version:   1.0
 */
public class Solution3 {


    public static String reverseWords(String s) {
        String trim = s.trim();
        String[] s1 = trim.split(" ");
        StringBuffer stringBuffer = new StringBuffer();
        for (int i = s1.length-1; i >=0 ; i--) {
            if ("".equals(s1[i])){
                continue;
            }
            stringBuffer.append(s1[i].trim());
            stringBuffer.append(" ");

        }
        String result=stringBuffer.toString();
        return  result.substring(0,result.length()-1);

    }

    public static void main(String[] args) {
        String s = "a good   example";
        System.out.println(reverseWords(s));
    }
}
